//声明 reducer 函数
// type 类型值在 redux 中必须是独一无二的. 如果重名, 会造成更新异常
// {type: 'ZAN_INCRE', payload: 1}
// {type: 'ZAN_DECRE', payload: 1}
let zanReducer = (state={value: 0}, action) => {
  //根据 type 的类型, 更新状态并返回
  switch(action.type){
    case 'ZAN_INCRE':
      return {
        value: state.value + action.payload
      }
    case 'ZAN_DECRE':
      return {
        value: state.value - action.payload
      }
    default:
      return state
  }
}

//暴露
export default zanReducer;

//声明函数创建 action 对象
export let zanIncreAction = (payload) => {
  return {
    type: 'ZAN_INCRE',
    payload: payload
  }
}

export let zanDecreAction = payload => ({type: 'ZAN_DECRE', payload});